package com.enjoyor.soa.traffic.server.efoms.dubbo.manage;

import com.alibaba.dubbo.config.annotation.Service;
import com.enjoyor.soa.traffic.api.dto.efoms.PingConnectHisDto;
import com.enjoyor.soa.traffic.core.efoms.domain.PingConnectHis;
import com.enjoyor.soa.traffic.core.efoms.service.IPingConnectHisService;
import com.enjoyor.soa.traffic.util.enums.EnumAppCode;
import com.enjoyor.soa.traffic.util.helper.LoggerHelper;
import com.enjoyor.soa.traffic.util.helper.ReflectHelper;
import com.enjoyor.soa.traffic.util.helper.ResultHelper;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class ManagePingConnectHisService {

    @Autowired
    private IPingConnectHisService pingConnectHisService;

    /**
     * 查询网络历史数据
     * @param pingHisId 网络历史编号
     * @param devCategoryCode 设备种类编号
     * @param devTypeCode 设备类型编号
     * @param devId 设备编号
     * @param devName 设备名称
     * @param creatStartTime 记录开始时间
     * @param creatEndTime 记录结束时间
     * @return
     */
	public ResultPojo selectPingConnectHisList(String pingHisId, String devCategoryCode, String devTypeCode,
			String devId, String devName, String creatStartTime, String creatEndTime) {
        try {
			List<PingConnectHis> pingConnectHisList = pingConnectHisService.selectPingConnectHisList(pingHisId,
					devCategoryCode, devTypeCode, devId, devName, creatStartTime, creatEndTime);
			List<PingConnectHisDto> pingConnectHisDtoList = ReflectHelper.listToList(pingConnectHisList,
					PingConnectHisDto.class);
			return ResultHelper.getResult(pingConnectHisDtoList);
        } catch (Exception e) {
            LoggerHelper.LOG.error(e);
            return ResultHelper.getResult(e, EnumAppCode.OPERATOR_FAILURE);
        }
    }
    
    /**
     * 新增网络历史数据
     * @param pingConnectHisDto
     * @param username
     */
    public ResultPojo insertPingConnectHis(PingConnectHisDto pingConnectHisDto, String username) {
        try {
            if (pingConnectHisDto == null)
                return ResultHelper.getResult(EnumAppCode.PARAM_ERR);
            PingConnectHis pingConnectHis = ReflectHelper.beanToBean(pingConnectHisDto, PingConnectHis.class);
            String pingHisId = pingConnectHisService.insertPingConnectHis(pingConnectHis, username);
            return ResultHelper.getResult(pingHisId);
        } catch (Exception e) {
            LoggerHelper.LOG.error(e);
            return ResultHelper.getResult(e, EnumAppCode.OPERATOR_FAILURE);
        }
    }

    /**
     * 修改网络历史数据
     * @param pingConnectHisDto
     * @param username
     */
    public ResultPojo updatePingConnectHis(PingConnectHisDto pingConnectHisDto, String username) {
        try {
            if (pingConnectHisDto == null || pingConnectHisDto.getPingHisId() == null || 
            		pingConnectHisDto.getPingHisId().equals(""))
            	return ResultHelper.getResult(EnumAppCode.PARAM_ERR);
            PingConnectHis pingConnectHis = ReflectHelper.beanToBean(pingConnectHisDto, PingConnectHis.class);
            String pingHisId = pingConnectHisService.updatePingConnectHis(pingConnectHis, username);
            return ResultHelper.getResult(pingHisId);
        } catch (Exception e) {
            LoggerHelper.LOG.error(e);
            return ResultHelper.getResult(e, EnumAppCode.OPERATOR_FAILURE);
        }

    }

    /**
     * 删除网络历史数据
     * @param pingHisId
     * @param username
     */
    public ResultPojo deletePingConnectHis(String pingHisId, String username) {
        try {
            if (pingHisId == null || pingHisId.equals(""))
                return ResultHelper.getResult(EnumAppCode.PARAM_ERR);
            pingConnectHisService.deletePingConnectHis(pingHisId, username);
            return ResultHelper.getResult(pingHisId);
        } catch (Exception e) {
            LoggerHelper.LOG.error(e);
            return ResultHelper.getResult(e, EnumAppCode.OPERATOR_FAILURE);
        }
    }
}
